
Partial Class BReg
    Inherits System.Web.UI.Page

    Dim secCode

    Protected Sub BReg_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Response.Cache.SetCacheability(HttpCacheability.NoCache)
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("type") <> "" Then
            Response.Redirect("Error.aspx")
            Exit Sub
        End If

        If Me.IsPostBack = False Then
            Dim a As New Globo
            a.executesql("select * from Countries", False)
            ddlCon.Items.Clear()
            While a.dr.Read = True
                ddlCon.Items.Add(a.dr(0))
            End While
            ddlCon.SelectedIndex = 110

            Dim b As New Globo
            b.executesql("select * from domain", False)
            While b.dr.Read = True
                ddlEmail.Items.Add(b.dr(0))
            End While
            b.dr.Close()
        End If

    End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        'Blank Filed Validation Check
        '++++++++++++++++++++++++++++++++++++++++++
        If txtUEmail.Text = "" Then
            lblErr.Text = "Enter Email ID"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtPswd.Text = "" Then
            lblErr.Text = "Enter Password"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtRePswd.Text = "" Then
            lblErr.Text = "Retype Password"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtUName.Text = "" Then
            lblErr.Text = "Enter Username"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtFname.Text = "" Then
            lblErr.Text = "Enter Buyer Name"
            lblErr.Visible = True
            Exit Sub
        End If

        If ddlCon.Text = "" Then
            lblErr.Text = "Select Country"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtLoc.Text = "" Then
            lblErr.Text = "Enter Your Location"
            lblErr.Visible = True
            Exit Sub
        End If

        If txtConPer.Text = "" Then
            lblErr.Text = "Enter Contact Person Details"
            lblErr.Visible = True
            Exit Sub
        End If

        If chkEULA.Checked = False Then
            lblErr.Text = "Plese accept the Terms & Conditions to continue.."
            lblErr.Visible = True
            Exit Sub
        End If


        '++++++++++++++++++++++++++++++++++++++++++
        'password mismatch validation check
        '``````````````````````````````````````````
        If txtPswd.Text <> txtRePswd.Text Then
            lblErr.Text = "Password Mismatch"
            lblErr.Visible = True
            Exit Sub
        End If


        '___________________________________________
        'Duplicate Data Entry Validation
        '#######################################################
        Dim c As New Globo
        c.executesql("select * from buyers where bEmail = '" & txtUEmail.Text & "'", False)
        If c.dr.Read = True Then
            lblErr.Text = "Email Id already Registered"
            lblErr.Visible = True
            c.dr.Close()
            Exit Sub
        End If

        Dim u, b As New Globo
        u.executesql("select * from users where uid = '" & txtUName.Text & "'", False)
        'Dim b As New Globo
        b.executesql("select * from buyers where buyer_id = '" & txtUName.Text & "'", False)
        If b.dr.Read = True Then
            lblErr.Text = "Buyer ID Unavailable"
            lblErr.Visible = True
            b.dr.Close()
            Exit Sub
        End If


        '#######################################################
        'Generation of buyer Secret code
        '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        Dim d As New Globo
        d.executesql("select * from buyers", False)
        Dim x As Integer
        If Not d.dr.Read Then
            x = 1
        Else
            x = d.dr.FieldCount + 1
        End If
        x = x + 10000
        secCode = txtUName.Text & x

        Session("seccode") = secCode


        '#######################################################
        'Data Insertion
        '*******************************************************
        Dim email As String
        email = txtUEmail.Text & "@" & ddlEmail.Text

        Dim a As New Globo
        a.executesql("insert into buyers values ('" & txtUName.Text & "', '" & txtFname.Text & "', '" & txtLoc.Text & "', '" & ddlCon.Text & "', '" & txtConPer.Text & "', '" & email & "','" & a.oCrypto.EncryptTripleDES(txtPswd.Text, Globo.sEncryptionKey).Replace("'", "''") & "', '" & secCode & "')", True)
        MsgBox("New buyer created." & vbCrLf & "Please login to continue..       ", MsgBoxStyle.OkOnly, "Buyer registration confirmation")

        '*******************************************************
        Server.Transfer("Loading.aspx")
    End Sub

    '_____________________________________________________________________________________________________________
    '*************************************************************************************************************
    Protected Sub lnkAboutUs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkAboutUs.Click
        Response.Redirect("AboutUs.aspx")
    End Sub

    Protected Sub lnkTermCond_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkTermCond.Click
        Response.Redirect("TermsConditions.aspx")
    End Sub

    Protected Sub lnkContactUs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkContactUs.Click
        Response.Redirect("ContactUs.aspx")
    End Sub

    Protected Sub lnkFAQs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFAQs.Click
        Response.Redirect("FAQs.aspx")
    End Sub

    Protected Sub lnkFeedback_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFeedback.Click
        Response.Redirect("Feedback.aspx")
    End Sub
End Class